<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">
    <H1>
      <xsl:value-of select="TEAM/COMPANYNAME"/>
    </H1>
    <H4>Last Manager Update:<xsl:value-of select="TEAM/HISTORY/UPDATE"/></H4>
    <HR/>
    <table border="1">
      <th>P</th>
      <th>W</th>
      <th>D</th>
      <th>L</th>
      <th>F</th>
      <th>A</th>
      <th>PTS</th>
	<th>MANAGERS COMMENTS</th>
      <TR>
        <TD>
          <xsl:value-of select="TEAM/HISTORY/RESULTS/PYD"/>
        </TD>
        <TD>
          <xsl:value-of select="TEAM/HISTORY/RESULTS/WON"/>
        </TD>
        <TD>
          <xsl:value-of select="TEAM/HISTORY/RESULTS/DWN"/>
        </TD>
        <TD>
          <xsl:value-of select="TEAM/HISTORY/RESULTS/LST"/>
        </TD>
        <TD>
          <xsl:value-of select="TEAM/HISTORY/RESULTS/FOR"/>
        </TD>
        <TD>
          <xsl:value-of select="TEAM/HISTORY/RESULTS/AGT"/>
        </TD>
        <TD>
          <xsl:value-of select="TEAM/HISTORY/RESULTS/PTS"/>
        </TD>
	<TD>
          <TEXTAREA Name="Mancom" Style="color:red" onblur="updateNode('/TEAM[0]/HISTORY[0]/MESSAGE[0]',this,9,9)" onkeypress='return letternumber(event,"b")'><xsl:value-of select="TEAM/HISTORY/MESSAGE"/></TEXTAREA>
        </TD>
      </TR>
    </table>
	
    <P>
      <BUTTON ONCLICK="window.open('./Help/Test2.html',null,'status=no menubar=no scrollbars=yes');">View HELP</BUTTON>
      <BUTTON ONCLICK="save();">SAVE LOCAL</BUTTON>
      <BUTTON ONCLICK="transform('PYR.xsl');">PLAYER</BUTTON>
      <BUTTON ONCLICK="updatexml();">UPLOAD</BUTTON>
      <BUTTON ONCLICK="loadType='ud';loadDoc();">RESET</BUTTON>
    </P>
    <table border="10" cellpadding="0" cellspacing="10" style="display: block" bgcolor="cccccc" class="1">
      <xsl:apply-templates/>
    </table>
  </xsl:template>
  <xsl:template match="*[text()]"/>
  <xsl:template match="PEOPLE/*/NAME[text()]">
    <xsl:call-template name="textrun"/>
  </xsl:template>
  <xsl:template name="textrun">
    <xsl:choose>
      <xsl:when test="@RNAME">
        <td>
          <xsl:value-of select="@RNAME"/>
        </td>
      </xsl:when>
    </xsl:choose>
    <xsl:choose>
      <xsl:when test="@IA">
        <td>
          <xsl:if test="parent::*/NAME='XX'">
            <xsl:value-of select="parent::*/TITLE[(.)]"/>
          </xsl:if>
          <xsl:if test="parent::*/TITLE='YY'">
            <xsl:call-template name="input"/>
          </xsl:if>
        </td>
      </xsl:when>
      <xsl:when test="@IB">
        <td>
          <xsl:if test="parent::*/TITLE='XX'">
            <xsl:value-of select="parent::*/NAME[(.)]"/>
          </xsl:if>
          <xsl:if test="parent::*/TITLE='YY'">
            <xsl:call-template name="inputA"/>
          </xsl:if>
        </td>
      </xsl:when>
      <xsl:when test="@IM">
        <td>
          <img>
            <xsl:attribute name="src">./images/Image-<xsl:value-of select="."/>.gif</xsl:attribute>
            <xsl:attribute name="width">40</xsl:attribute>
            <xsl:attribute name="height">40</xsl:attribute>
            <xsl:attribute name="onclick">updateImage('<xsl:for-each select="ancestor-or-self::*">/<xsl:value-of select="name()"/>[<xsl:value-of select="count(preceding-sibling::*[name(current()) = name()])"/>]</xsl:for-each>',this,<xsl:value-of select="@ID"/>,1)</xsl:attribute>
          </img>
        </td>
      </xsl:when>
      <xsl:when test="@IDT">
        <td>
          <img>
            <xsl:attribute name="src">./images/Pos-<xsl:value-of select="."/>.gif</xsl:attribute>
            <xsl:attribute name="width">40</xsl:attribute>
            <xsl:attribute name="height">50</xsl:attribute>
            <xsl:attribute name="onclick">updateImage('<xsl:for-each select="ancestor-or-self::*">/<xsl:value-of select="name()"/>[<xsl:value-of select="count(preceding-sibling::*[name(current()) = name()])"/>]</xsl:for-each>',this,<xsl:value-of select="@ID"/>,1)</xsl:attribute>
          </img>
        </td>
      </xsl:when>

      <xsl:when test="@IDR">
        <td>
          <input>
            <xsl:attribute name="type">CHECKBOX</xsl:attribute>
            <xsl:attribute name="onclick">updateCheck('<xsl:for-each select="ancestor-or-self::*">/<xsl:value-of select="name()"/>[<xsl:value-of select="count(preceding-sibling::*[name(current()) = name()])"/>]</xsl:for-each>',this)</xsl:attribute>
            <xsl:attribute name="name">
              <xsl:value-of select="@IDR"/>
            </xsl:attribute>
            <xsl:if test="self::HOME[(.)='-1']">
              <xsl:attribute name="checked"/>
            </xsl:if>
          </input>
        </td>
      </xsl:when>

      <xsl:when test="@IP">
        <td>
          <xsl:call-template name="inputA"/>
        </td>
      </xsl:when>
      <xsl:otherwise>
        <td>
          <xsl:call-template name="inputA"/>
        </td>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:choose>
      <xsl:when test="@NR">
        <tr class="1" valign="top"/>
      </xsl:when>
      <xsl:when test="@HR"/>
    </xsl:choose>
  </xsl:template>
  <xsl:template match="PEOPLE/*[text()]">
    <xsl:call-template name="textrun"/>
  </xsl:template>
  <xsl:template match="PEOPLE/SELECT">
    <xsl:call-template name="textrun"/>
  </xsl:template>
  <xsl:template match="PEOPLE/PLAYER"/>
  <xsl:template name="input">
    <input>
      <xsl:attribute name="onblur">updateNode('<xsl:for-each select="ancestor-or-self::*">/<xsl:value-of select="name()"/>[<xsl:value-of select="count(preceding-sibling::*[name(current()) = name()])"/>]</xsl:for-each>',this,<xsl:value-of select="@IA"/>,<xsl:value-of select="@ID"/>)</xsl:attribute>
      <xsl:attribute name="size">4</xsl:attribute>
      <xsl:attribute name="value">
        <xsl:value-of select="."/>
      </xsl:attribute>
      <xsl:attribute name="type">text</xsl:attribute>
      <xsl:attribute name="onKeyPress">return letternumber(event,"1")</xsl:attribute>
      <xsl:if test="@LEN">
        <xsl:attribute name="maxlength">
          <xsl:value-of select="@LEN"/>
        </xsl:attribute>
      </xsl:if>
    </input>
  </xsl:template>
  <xsl:template name="inputA">
    <input>
      <xsl:attribute name="onblur">updateNode('<xsl:for-each select="ancestor-or-self::*">/<xsl:value-of select="name()"/>[<xsl:value-of select="count(preceding-sibling::*[name(current()) = name()])"/>]</xsl:for-each>',this,9,9)</xsl:attribute>
      <xsl:attribute name="size">10</xsl:attribute>
      <xsl:attribute name="value">
        <xsl:value-of select="."/>
      </xsl:attribute>
      <xsl:attribute name="type">text</xsl:attribute>
      <xsl:attribute name="onKeyPress">return letternumber(event,"a")</xsl:attribute>
      <xsl:if test="@LEN">
        <xsl:attribute name="maxlength">
          <xsl:value-of select="@LEN"/>
        </xsl:attribute>
      </xsl:if>
    </input>
  </xsl:template>
</xsl:stylesheet>
